home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 January: Mac OS SDK / Dev.CD Jan 97 SDK2.toast / Development Kits (Disc 2) / OpenDoc Development Framework / ODFDev / ODF / OS / FWGraphx / FWLinShp.cpp < prev    next >
Encoding:
Text File  |  1996-09-17  |  9.8 KB  |  354 lines  |  [TEXT/MPS ]

  1. //========================================================================================
  2. //
  3. //    File:                FWLinShp.cpp
  4. //    Release Version:    $ ODF 2 $
  5. //
  6. //    Copyright:    (c) 1993 - 1996 by Apple Computer, Inc., all rights reserved.
  7. //
  8. //========================================================================================
  9.  
  10. #include "FWOS.hpp"
  11.  
  12. #ifndef FWLINSHP_H
  13. #include "FWLinShp.h"
  14. #endif
  15.  
  16. #ifndef SLGRGLOB_H
  17. #include "SLGrGlob.h"
  18. #endif
  19.  
  20. #ifndef FWGC_H
  21. #include "FWGC.h"
  22. #endif
  23.  
  24. #ifndef FWINK_H
  25. #include "FWInk.h"
  26. #endif
  27.  
  28. #ifndef FWSTYLE_H
  29. #include "FWStyle.h"
  30. #endif
  31.  
  32. #ifndef FWGRUTIL_H
  33. #include "FWGrUtil.h"
  34. #endif
  35.  
  36. #ifndef SLRENDER_H
  37. #include "SLRender.h"
  38. #endif
  39.  
  40. // ----- Foundation Includes -----
  41.  
  42. #ifndef FWSTREAM_H
  43. #include "FWStream.h"
  44. #endif
  45.  
  46. // ----- OpenDoc Includes -----
  47.  
  48. #ifndef _TRANSFORM_
  49. #include <Trnsform.xh>
  50. #endif
  51.  
  52. //========================================================================================
  53. // File scope definitions
  54. //========================================================================================
  55.  
  56. #ifdef FW_BUILD_MAC
  57. #pragma segment FWGraphics_LineShape
  58. #endif
  59.  
  60. //========================================================================================
  61. //    class FW_CLineShape
  62. //========================================================================================
  63.  
  64. FW_DEFINE_AUTO(FW_CLineShape)
  65. FW_DEFINE_CLASS_M1(FW_CLineShape, FW_CShape)
  66.  
  67. // This class is archivable, but we provide the archiving implementation in a separate
  68. // translation unit in order to enable deadstripping of the archiving-related code
  69. // in parts that do not use archiving with this class.
  70.  
  71. //----------------------------------------------------------------------------------------
  72. //    FW_CLineShape::FW_CLineShape
  73. //----------------------------------------------------------------------------------------
  74.  
  75. FW_CLineShape::FW_CLineShape(const FW_CLineShape& other) :
  76.     FW_CShape(other),
  77.     fStart(other.fStart),
  78.     fEnd(other.fEnd)
  79. {
  80.     FW_END_CONSTRUCTOR
  81. }
  82.  
  83. //----------------------------------------------------------------------------------------
  84. //    FW_CLineShape::FW_CLineShape
  85. //----------------------------------------------------------------------------------------
  86.  
  87. FW_CLineShape::FW_CLineShape() :
  88.     FW_CShape(FW_kFrame, FW_kNormalInk, FW_kNormalStyle, FW_kNormalFont)
  89.         // fStart and fEnd are initialzied to 0's by default constructors
  90. {
  91.     FW_END_CONSTRUCTOR
  92. }
  93.  
  94. //----------------------------------------------------------------------------------------
  95. //    FW_CLineShape::FW_CLineShape
  96. //----------------------------------------------------------------------------------------
  97.  
  98. FW_CLineShape::FW_CLineShape(FW_Fixed xStart, FW_Fixed yStart,
  99.                              FW_Fixed xEnd, FW_Fixed yEnd,
  100.                                const FW_CInk& ink,
  101.                                const FW_CStyle& style) :
  102.     FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
  103.     fStart(xStart, yStart),
  104.     fEnd(xEnd, yEnd)
  105. {
  106.     FW_END_CONSTRUCTOR
  107. }
  108.  
  109. //----------------------------------------------------------------------------------------
  110. //    FW_CLineShape::FW_CLineShape
  111. //----------------------------------------------------------------------------------------
  112.  
  113. FW_CLineShape::FW_CLineShape(const FW_CPoint& start,
  114.                              const FW_CPoint& end,
  115.                                const FW_CInk& ink,
  116.                                const FW_CStyle& style) :
  117.     FW_CShape(FW_kFrame, ink, style, FW_kNormalFont),
  118.     fStart(start),
  119.     fEnd(end)
  120. {
  121.     FW_END_CONSTRUCTOR
  122. }
  123.  
  124. //----------------------------------------------------------------------------------------
  125. //    FW_CLineShape::FW_CLineShape
  126. //----------------------------------------------------------------------------------------
  127.  
  128. FW_CLineShape::FW_CLineShape(FW_CReadableStream& stream) :
  129.     FW_CShape(stream)
  130. {
  131.     stream >> fStart;
  132.     stream >> fEnd;
  133.     FW_END_CONSTRUCTOR
  134. }
  135.  
  136. //----------------------------------------------------------------------------------------
  137. //    FW_CLineShape::~FW_CLineShape
  138. //----------------------------------------------------------------------------------------
  139.  
  140. FW_CLineShape::~FW_CLineShape()
  141. {
  142.     FW_START_DESTRUCTOR
  143. }
  144.  
  145. //----------------------------------------------------------------------------------------
  146. //    FW_CLineShape::operator=
  147. //----------------------------------------------------------------------------------------
  148.  
  149. FW_CLineShape& FW_CLineShape::operator=(const FW_CLineShape& other)
  150. {
  151.     if (this != &other)
  152.     {
  153.         FW_CShape::operator=(other);
  154.     
  155.         fStart = other.fStart;
  156.         fEnd = other.fEnd;
  157.     }
  158.     
  159.     return *this;
  160. }
  161.  
  162. //----------------------------------------------------------------------------------------
  163. //    FW_CLineShape::Render
  164. //----------------------------------------------------------------------------------------
  165.  
  166. void FW_CLineShape::Render(FW_CGraphicContext& gc) const
  167. {    
  168.     FW_PrivRenderLine(gc.GetEnvironment(),
  169.         gc,
  170.         fStart, fEnd,
  171.         GetRenderVerb(),
  172.         fInk,
  173.         fStyle);
  174.     FW_FailOnEvError(gc.GetEnvironment());
  175. }
  176.  
  177. //----------------------------------------------------------------------------------------
  178. //    FW_CLineShape::RenderLine
  179. //----------------------------------------------------------------------------------------
  180.  
  181. void FW_CLineShape::RenderLine(FW_CGraphicContext& gc,
  182.                                 const FW_CPoint& start, 
  183.                                 const FW_CPoint& end,
  184.                                 const FW_CInk& ink,
  185.                                 const FW_CStyle& style)
  186. {
  187.     FW_PrivRenderLine(gc.GetEnvironment(),
  188.         gc,
  189.         start, end,
  190.         FW_kFrame,
  191.         ink,
  192.         style);
  193.     FW_FailOnEvError(gc.GetEnvironment());
  194. }
  195.  
  196. //----------------------------------------------------------------------------------------
  197. //    FW_CLineShape::GetBounds
  198. //----------------------------------------------------------------------------------------
  199.  
  200. void FW_CLineShape::GetBounds(FW_CGraphicContext& gc, FW_CRect& rect) const
  201. {
  202. FW_UNUSED(gc);
  203.  
  204.     rect.Set(fStart.x, fStart.y, fEnd.x, fEnd.y);
  205.     rect.Sort();
  206.     FW_Fixed halfPen = FW_Half(GetPenSize());
  207.     rect.Inset(-halfPen, -halfPen);
  208. }
  209.  
  210. //----------------------------------------------------------------------------------------
  211. //    FW_CLineShape::GetAnchorPoint
  212. //----------------------------------------------------------------------------------------
  213.  
  214. FW_CPoint FW_CLineShape::GetAnchorPoint() const
  215. {
  216.     FW_CRect rect(fStart.x, fStart.y, fEnd.x, fEnd.y);
  217.     rect.Sort();
  218.     FW_Fixed halfPen = FW_Half(GetPenSize());
  219.     rect.Inset(-halfPen, -halfPen);
  220.     
  221.     return rect.TopLeft();
  222. }
  223.  
  224. //----------------------------------------------------------------------------------------
  225. //    FW_CLineShape::Transform
  226. //----------------------------------------------------------------------------------------
  227.  
  228. void FW_CLineShape::Transform(Environment *ev, ODTransform* transform)
  229. {
  230.     fStart.Transform(ev, transform);
  231.     fEnd.Transform(ev, transform);
  232. }
  233.  
  234. //----------------------------------------------------------------------------------------
  235. //    FW_CLineShape::InverseTransform
  236. //----------------------------------------------------------------------------------------
  237.  
  238. void FW_CLineShape::InverseTransform(Environment *ev, ODTransform* transform)
  239. {
  240.     fStart.InverseTransform(ev, transform);
  241.     fEnd.InverseTransform(ev, transform);
  242. }
  243.  
  244. //----------------------------------------------------------------------------------------
  245. //    FW_CLineShape::Inset
  246. //----------------------------------------------------------------------------------------
  247.  
  248. void FW_CLineShape::Inset(FW_Fixed x, FW_Fixed y)
  249. {
  250.     if (fStart.x > fEnd.x)
  251.     {
  252.         fStart.x -= x;
  253.         fEnd.x += x;
  254.     }
  255.     else if (fStart.x < fEnd.x)
  256.     {
  257.         fStart.x += x;
  258.         fEnd.x -= x;
  259.     } // if fStart.x == fEnd.x don't do anything
  260.  
  261.     if (fStart.y > fEnd.y)
  262.     {
  263.         fStart.y -= y;
  264.         fEnd.y += y;
  265.     }
  266.     else if (fStart.y < fEnd.y)
  267.     {
  268.         fStart.y += y;
  269.         fEnd.y -= y;
  270.     } // if fStart.y == fEnd.y don't do anything
  271. }
  272.  
  273. //----------------------------------------------------------------------------------------
  274. //    FW_CLineShape::MoveShape
  275. //----------------------------------------------------------------------------------------
  276.  
  277. void FW_CLineShape::MoveShape(FW_Fixed deltaX, FW_Fixed deltaY)
  278. {
  279.     fStart.x += deltaX;
  280.     fStart.y += deltaY;
  281.     fEnd.x += deltaX;
  282.     fEnd.y += deltaY;
  283. }
  284.  
  285. //----------------------------------------------------------------------------------------
  286. //    FW_CLineShape::MoveShapeTo
  287. //----------------------------------------------------------------------------------------
  288.  
  289. void FW_CLineShape::MoveShapeTo(FW_Fixed x, FW_Fixed y)
  290. {
  291.     fEnd.x += x - fStart.x;
  292.     fEnd.y += y - fStart.y;
  293.     fStart.x = x;
  294.     fStart.y = y;
  295. }
  296.  
  297. //----------------------------------------------------------------------------------------
  298. //    FW_CLineShape::HitTest
  299. //----------------------------------------------------------------------------------------
  300.  
  301. FW_Boolean FW_CLineShape::HitTest(FW_CGraphicContext& gc,
  302.                                   const FW_CPoint& test,
  303.                                   FW_Fixed tolerance) const
  304. {
  305. FW_UNUSED(gc);
  306.     if(fRenderVerb == FW_kNoRendering)
  307.         return FALSE;
  308.  
  309.     return ::FW_HitTestLine(fStart, fEnd, test, tolerance);
  310. }
  311.  
  312. //----------------------------------------------------------------------------------------
  313. //    FW_CLineShape::Copy
  314. //----------------------------------------------------------------------------------------
  315.  
  316. FW_CShape* FW_CLineShape::Copy() const
  317. {
  318.     return FW_NEW(FW_CLineShape, (*this));
  319. }
  320.  
  321. //----------------------------------------------------------------------------------------
  322. //    FW_CLineShape::GetGeometry
  323. //----------------------------------------------------------------------------------------
  324.  
  325. void FW_CLineShape::GetGeometry(FW_CPoint& start, FW_CPoint& end) const
  326. {
  327.     start = fStart;
  328.     end = fEnd;
  329. }
  330.  
  331.  
  332. //----------------------------------------------------------------------------------------
  333. //    FW_CLineShape::SetGeometry
  334. //----------------------------------------------------------------------------------------
  335.  
  336. void FW_CLineShape::SetGeometry(const FW_CPoint& start, const FW_CPoint& end)
  337. {
  338.     fStart = start;
  339.     fEnd = end;
  340. }
  341.  
  342. //----------------------------------------------------------------------------------------
  343. //    FW_CLineShape::Flatten
  344. //----------------------------------------------------------------------------------------
  345.  
  346. void FW_CLineShape::Flatten(FW_CWritableStream& stream) const
  347. {
  348.     FW_CShape::Flatten(stream);
  349.     
  350.     stream << fStart;
  351.     stream << fEnd;
  352. }
  353.  
  354.